package com.itboye.ihomebank.activity.finance;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.activity.me.ActivityHuajKuanPay;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.base.MyApplcation;
import com.itboye.ihomebank.bean.HuanKuansBean;
import com.itboye.ihomebank.util.DoubleUtil;

import static com.itboye.ihomebank.util.TimesUtils.getStringToDateFour;


/**
 * A login screen that offers login via email/password.
 */
public class HuanKuanDetailActivity extends BaseOtherActivity {
    TextView txt_title;
    ImageView img_back;
    Button btn_huankuan;
    TextView txt_method, txt_date, txt_money, txt_benjin, txt_lixi,txt_zhinajin;
    int itemId, position;
    HuanKuansBean huanKUanDetailBean;
    HuanKuansBean.Plan planModel;
    MyApplcation myApp;

    @Override
    protected int layout_id() {
        return R.layout.activity_huan_kuan_detail;
    }

    @Override
    protected void onInitController() {

    }

    @Override
    protected void onInit() {
        myApp = (MyApplcation) getApplication();
        myApp.HuanKuanDetailUI = this;
        txt_title.setText("还款详情");

        huanKUanDetailBean = (HuanKuansBean) getIntent().getSerializableExtra("model");
        planModel = huanKUanDetailBean.getPlan().get(position);
        itemId = getIntent().getIntExtra("item_id", 0);
        position = getIntent().getIntExtra("position", 0);
        setData();
    }

    private void setData() {
        txt_money.setText(DoubleUtil.doubleTransform(planModel.getTotal()));//还款本金
        txt_date.setText(getStringToDateFour(planModel.getCan_pay_end() + "") + "应该还款（元）");
        txt_benjin.setText(DoubleUtil.doubleTransform(String.valueOf(planModel.getPrincipal())));
        txt_lixi.setText(DoubleUtil.doubleTransform(String.valueOf(planModel.getAccrual())));
        txt_method.setText(huanKUanDetailBean.getDt_repayment_type_name());
        if (planModel.getOverdue_money().equals("")){
            txt_zhinajin.setText("无");
        }else{
            txt_zhinajin.setText(DoubleUtil.doubleTransform(planModel.getOverdue_money()));
        }

    }

    @Override
    protected void onReadIntent(Bundle bundle) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.btn_huankuan:
                Intent intent = new Intent(this, ActivityHuajKuanPay.class);
                intent.putExtra("model", planModel);
                startActivity(intent);
                break;
        }
    }
}

